package robot.map;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;

import robot.Robot;
import robot.RobotConsole;



public class MemoryMap extends RobotMap {

	private static final long serialVersionUID = -5369017136072213752L;
	private List<Dimension> targets;

	public MemoryMap(RobotConsole robotConsole, Robot robot) {
		super(robotConsole, robot);

		targets = new ArrayList<Dimension>();

		for (int i=1 ; i<33 ; i++) {
			if (i%2 == 1) {
				for (int j=1 ; j<33 ; j++) {
					targets.add(new Dimension(i*28, j*28));
				}
			}
			else {
				for (int j=32 ; j>0 ; j--) {
					targets.add(new Dimension(i*28, j*28));
				}
			}
		}
	}

	public void clearMap() {
		robotConsole.addText("Wyczyszczono pamięć robota");
	}

	public Dimension getTarget() {
		return targets.get(0);
	}

	public void targetHit() {
		targets.remove(0);
	}

	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);

		g.setColor(Color.RED);
		for (Dimension dimension : targets) {
			drawCross(dimension, g);
		}

		g.setColor(Color.ORANGE);
		g.drawLine(robot.getPosition().width, robot.getPosition().height,
				targets.get(0).width, targets.get(0).height);
	}

	private void drawCross(Dimension dimension, Graphics g) {
		g.drawLine(dimension.width-4, dimension.height, dimension.width+4, dimension.height);
		g.drawLine(dimension.width, dimension.height-4, dimension.width, dimension.height+4);
	}

}
